#include "ru_ntcreb_csir_libs_methods_SVCH_SVCHService.h"
#include "SVCHAlgorithmService.h"
#include <math.h>
#include <iostream>
#include "XMLBuilder.h"
#include "XMLParser.h"
extern "C"
	JNIEXPORT jstring JNICALL Java_ru_ntcreb_csir_libs_methods_SVCH_SVCHService_createSVCHImpulseXML

	(JNIEnv *env, jobject this_obj, jstring svchImpulseDTOXml_J){

		string svchImpulseDTOXml = env->GetStringUTFChars(svchImpulseDTOXml_J, NULL);
		shared_ptr<SVCHImpulseDTO> svchImpulseDTO_shared = parseSvchDTOXml(svchImpulseDTOXml);
		map <double,double> svchMap = createSVCHImpulse(svchImpulseDTO_shared.get());
		char* result = createSVCHArrayXML(svchMap);
		return env->NewStringUTF(result);
}


extern "C"	JNIEXPORT jstring JNICALL Java_ru_ntcreb_csir_libs_methods_SVCH_SVCHService_createTractSVCHReactionXML
	(JNIEnv *env, jobject obj,jstring svchReactionInput){

		string svchReactionInput_C = env->GetStringUTFChars(svchReactionInput, NULL);
		TractSVCHReactionInputDTO* dto = parseTractSVCHReactionInputXML(svchReactionInput_C);
		map<double,double> svchReactionMap = createTractSVCHReaction(dto->svchMap,*(dto->tractVector.at(0)),*(dto->tractVector.at(1)));
		char* result = createTractSVCHReactionXML(svchReactionMap);
		return env->NewStringUTF(result);
}



extern "C" JNIEXPORT jdoubleArray JNICALL Java_ru_ntcreb_csir_libs_methods_SVCH_SVCHService_createTractSVCHFrequencyReactionXML
	(JNIEnv *env, jobject obj,jdoubleArray svchImpulseVoltageArray,jobject tractDTO1,jobject tractDTO2,jint arrLenght){

		jdoubleArray result = env->NewDoubleArray(arrLenght); 

		/*jdoublearray tractsvchreactionarr = java_ru_ntcreb_csir_libs_methods_svch_svchservice_createtractsvchreaction(env,obj,svchimpulsevoltagearray,arrlenght,tractdto1,tractdto2);

		double* temparray = env->getdoublearrayelements(tractsvchreactionarr, null);

		double* svchfrequencyreactionarray = createtractsvchfrequencyreaction(temparray,arrlenght);*/

		double* temparray = env->GetDoubleArrayElements(svchImpulseVoltageArray, NULL);
		createTractSVCHFrequencyReaction(temparray,arrLenght);

		//env->ReleaseDoubleArrayElements(result,svchfrequencyreactionarray,0);

		return result;

}